package com.thread;

/**
 * @author :admin
 * @description: 死锁举例, synchronized锁定当前类，若其中一个线程持有未释放，其他线程不可能获取锁
 * @create date: 2019/4/3 16:04
 */
public class DealthThread1 {

    public static void main(String[] args) throws InterruptedException {
        ThreadStu1 numRef = new ThreadStu1();
        ThreadA1 athread = new ThreadA1(numRef);
        athread.start();
//        Thread.sleep(2000);
        ThreadB1 bthread = new ThreadB1(numRef);
        bthread.start();
    }
}

class ThreadA1 extends Thread {
    ThreadStu1 threadStu;

    public ThreadA1(ThreadStu1 threadStu) {
        this.threadStu = threadStu;
    }

    public void run() {
        threadStu.addNumA("a");
    }
}

class ThreadB1 extends Thread {
    ThreadStu1 threadStu;

    public ThreadB1(ThreadStu1 threadStu) {
        this.threadStu = threadStu;
    }

    public void run() {
        threadStu.addNumB("b");
    }

}

class ThreadStu1 {
    synchronized public void addNumA(String name) {
        System.out.println("methodA begin");
        boolean isContinueRun = true;
        while (isContinueRun) {
//            System.out.println("deal while");
        }
        System.out.println("methodA end");

    }

    synchronized public void addNumB(String name) {
        System.out.println("methodB begin");
        System.out.println("methodB end");
    }
}